import java.util.Random;
public class copy{
    public static void main(String[] args){
        Random r = new Random();

        System.out.println("随机生成一个数组：");
        int[] array = new int[10];
        for(int i = 0; i < array.length; i++){
            int a = r.nextInt(11);
            array[i] = a;
        }
            System.out.println("数组遍历为：");
            for(int i = 0 ; i < array.length ; i++){
                System.out.print(array[i] + " ");
        }
        System.out.println(" ");

        int[] copyArr = copyOfRange(array, 3, 7);
        
        System.out.println("遍历新数组");
        for(int i = 0 ; i < copyArr.length ; i++){
            System.out.print(copyArr[i] + " ");
        }
    }
    //将数组从索引from开始到to结束(不包含to)的元素复制到新数组中
    public static int[] copyOfRange(int[] arr, int from, int to){
        int[] newarr = new int[to - from];
        for(int i = from; i < to; i++){
            newarr[i - from] = arr[i];
        }
        return newarr;
    }
}